package cc.bailongma.me;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends Activity implements OnClickListener {

	private EditText et_phone;
	private EditText et_password;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		setView();
	}

	private void setView() {
		et_phone = (EditText) findViewById(R.id.et_login_phone);
		et_password = (EditText) findViewById(R.id.et_login_password);
		findViewById(R.id.tv_login).setOnClickListener(this);
		findViewById(R.id.tv_reg).setOnClickListener(this);
		
		TextView tv_forget_pwd=(TextView)findViewById(R.id.tv_forget_pwd);
		tv_forget_pwd.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		tv_forget_pwd.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_login:

			String phone = et_phone.getText().toString().trim();
			String password = et_password.getText().toString().trim();
			if (TextUtils.isEmpty(phone)) {
				et_phone.setError("手机不能为空");
				return;
			}
			if (TextUtils.isEmpty(password)) {
				et_password.setError("密码不能为空");
				return;
			}
			if("139".equals(phone)&&"1".equals(password)){
				startAty(MainActivity.class);
				finish();
			}else{
				Toast.makeText(this, "错误", 0).show();
			}
			break;
		case R.id.tv_reg:
			startAty(RegistActivity.class);
			break;
		case R.id.tv_forget_pwd:
			startAty(FindPwdActivity.class);
			break;
		}

	}

	private void startAty(Class<?> clz) {
		Intent intent=new Intent(this,clz);
		startActivity(intent);
	}
}
